package com.by.controller;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.SpringVersion;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.sql.SQLException;
import java.util.List;

/**
 * @author LittleDesire
 * @description
 * @date 2022-03-22 周二 17:37
 * @since 17
 */
@Controller
public class HomeController {
    @Autowired
    private QueryRunner run;

    @GetMapping("/hello")@ResponseBody
    public String hello() {
        return "hello 兆瓦";
    }

    @RequestMapping("/mes")
    public String mes(Model model) {
        model.addAttribute("version", SpringVersion.getVersion());
        List<String> list = null;
        try {
           list = run.query("show databases", new ColumnListHandler<>());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        model.addAttribute("dbs", list);
        return "mes";
    }
}
